define(function() {
	return function($compile, $scope) {
		require([ "PDUtilDir/dataService", "AppPathDir/spots/spotsTicketSearch/support", "PDUtilDir/util",
				"PDUtilDir/tool", "PDUtilDir/inputSelect" ], function( DataService, Support,
				Util, Tool, inputSelect) {
			/* 查询 start */
			$scope.cache = {
				typeArray : new Array(),
				typeMap : new Map()
				//D_SERVICE_ORG 服务机构
				//D_SERVICE_ORG_SUPPLIER 供应所
				//D_SERVICE_ORG_GROUP 组团社
			};
			$scope.search = {}
			$scope.searchSupport = {
				run : function() {
					$scope.grid.reload({
						queryParam : $scope.search
					})
				}
			};
			/* 详情 */
			$scope.detailSupport = {
				run : function(id) {
					var allData = $scope.grid.getAllData(), data = undefined;
					$.each(allData, function(index, row) {
						if(row.id == id){
							data = row;
							DataService.setObject("spotsTicket.search.reserve", data);
						}
					});
					window.top.tabs.addTab({
						id : data.id + '_stop_ticket_search',
						title : data.spotName || '门票预定',
						remote : {
							url : getServer()
									+ "/static/core/page/home/subHome.jsp",
							iframe : true,
							param : {
								html : getServer()
										+ "/static/app/spots/spotsTicketSearch/views/detail.html",
								ctrl : getServer()
										+ "/static/app/spots/spotsTicketSearch/detail.js",
								id : data.id
							}
						}
					});
				}
			};
			
			/* render grid */
			$scope.initSupport = {
				run : function() {
					if($scope.cache.typeArray.length > 0 && $scope.cache.currentOrgType){
						$scope.grid = Support.init($scope.cache, $scope.detailSupport, $scope.searchSupport);
					}
				}
			};
			
			//当前用户角色
			$.ajax({
				url : getServer() + "/flea/hclv/getCurrentOrgType.htmls",
				success : function(data) {
					$scope.cache.currentOrgType = data.data;
					DataService.setObject("global.current.orgType", $scope.cache.currentOrgType);
					$scope.initSupport.run();
				}
			});
			
			// 类型
			$.ajax({
				url : getServer() + "/flea/dict/initTree.htmls",
				async : false,
				data : {
					'dictCode' : 'D_SPOT_TICKET_TYPE'
				},
				success : function(data) {
					$scope.cache.typeArray = data;
					$.each(data, function(index, row) {
						$scope.cache.typeMap.set(row.dictCode, row.dictName);
					});
					DataService.setMap("DICT.D_SPOT_TICKET_TYPE.MAP", $scope.cache.typeMap);
					$scope.initSupport.run();
				}
			});
		})
	}
});